package com.yxq.mdt.app.modules.personal.model;

import com.yxq.mdt.app.base.RespBase;
import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.auction.bean.AuctionProfitBean;
import com.yxq.mdt.app.modules.auction.bean.SendGoodsNum;
import com.yxq.mdt.app.modules.auction.model.AuctionApi;
import com.yxq.mdt.app.modules.personal.bean.MainPersonTokenBean;
import com.yxq.mdt.app.modules.personal.bean.MainPersonalImNumber;
import com.yxq.mdt.app.modules.personal.bean.MainSaveAddImNumber;
import com.yxq.mdt.app.modules.personal.bean.MyPersonalBean;
import com.yxq.mdt.app.modules.personal.bean.RechargeRecordBean;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class MainPersonalModel implements IBaseModel {
    @Override
    public void onDestroy() {

    }

    //获取个人信息
    public static void getPersonalDate(String token, ApiModel.CommonCallback<MyPersonalBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainPersonalApi.class)
                .getPersonalModel(token)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MyPersonalBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MyPersonalBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }
    //获取im账号

    public void getImNumberData(ApiModel.CommonCallback<MainPersonalImNumber> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainPersonalApi.class)
                .getImData()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MainPersonalImNumber>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(MainPersonalImNumber baseEntity) throws Exception {
                        callback.onSuccess(baseEntity);
                    }

                });
    }

    //获取个人信息
    public void getTokenData(String token, ApiModel.CommonCallback<MainPersonTokenBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainPersonalApi.class)
                .getToken(token)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MainPersonTokenBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MainPersonTokenBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    //IM用户操作-新增、修改IM账号
    public void getImNumber(String nikeName, ApiModel.CommonCallback<MainPersonalImNumber> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainPersonalApi.class)
                .getSaveImUser(nikeName)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<MainPersonalImNumber>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(MainPersonalImNumber respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    /**
     * 我的支出
     *
     * @param orderByClause 降序：gco.add_time DESC；升序： gco.add_time ASC
     * @param pageNum
     * @param pageSize
     * @param callback
     */
    public void selectByPageList(String orderByClause, int pageNum, int pageSize, ApiModel.CommonCallback<RechargeRecordBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainPersonalApi.class)
                .selectByPageList(orderByClause, pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RechargeRecordBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(RechargeRecordBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    /**
     * 我的收益
     *
     * @param orderByClause 降序：gco.add_time DESC；升序： gco.add_time ASC
     * @param pageNum
     * @param pageSize
     * @param callback
     */
    public void selectEarningsByPageList(String orderByClause, int pageNum, int pageSize, ApiModel.CommonCallback<RechargeRecordBean> callback) {
        RetrofitFactory.getJavaRetrofit().create(MainPersonalApi.class)
                .selectEarningsByPageList(orderByClause, pageNum, pageSize)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RechargeRecordBean>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(RechargeRecordBean respBase) {
                        callback.onSuccess(respBase);
                    }
                });
    }

    //获取提现记录以及提现总金额
    public static void selectByOrderSendGoodsNum(ApiModel.CommonCallback<SendGoodsNum> callback) {
        RetrofitFactory.getPMRetrofit().create(MainPersonalApi.class)
                .selectByOrderSendGoodsNum()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<SendGoodsNum>() {
                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    protected void onSuccess(SendGoodsNum baseEntity) throws Exception {
                        callback.onSuccess(baseEntity);
                    }
                });
    }
}
